package com.niiwoo.activity.stage.enums.goods;

import java.util.ArrayList;
import java.util.List;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum GiftEnum {
  
	/**
     * 一级类型
     */
    ALL(1, 0, "全部"),
    LOAN(2, 0, "借款"),
    INVESTMENT(3, 0, "投资"),
    WITHDRAWALS(4, 0, "提现"),
    PROP(5, 0, "道具"),
    MATERIAL_OBJECT(6, 0, "实物"),
    
    /**
     * 借款
     */
    JIEKUAN_FXQ(100009, 2, "借款返现红包"),
    JIEKUAN_LILV_ZKK(100012, 2, "借款利率折扣卡"),
    
    /**
     * 投资
     */
    TOUZI_JXQ(100006, 3, "投资加息券"),
    DANBAO_FXQ(100007, 3, "担保返现红包"),
    TOUZI_FXQ(100008, 3, "投资返现红包"),
    
    /**
     * 提现
     */
    TIXIAN_HB(100010, 4, "提现红包"),
    
    /**
     * 道具
     */
    JIFEN_KA(101004, 5, "积分"),
    BUQIAN_KA(101006, 5, "签到补签卡"),
    CHOUJIANG_KA(101007, 5, "抽奖卡");
    
    /**
     * 实物
     */
    private Integer id;
    private Integer parentId;
    private String typeName;
    
    public static List<GiftEnum>getAllChildType(int parentId){
    	List<GiftEnum>list=new ArrayList<GiftEnum>();
    	for(GiftEnum g:GiftEnum.values()){
    		if(g.getParentId()==parentId){
    			list.add(g);
    		}
    	}
    	return list;
    }

    /**
   	 * 递归获取顶级枚举
   	 * 
   	 * @param id
   	 * @return
   	 */
   	public static GiftEnum getTopGiftEnum(Integer id) {
   		if (id == null) {
   			return null;
   		}
   		for (GiftEnum goodsTypeDicEnum : GiftEnum.values()) {
   			if (goodsTypeDicEnum.getId().equals(id)) {
   				if (goodsTypeDicEnum.getParentId() ==0) {
   					return goodsTypeDicEnum;
   				} else {
   					return getTopGiftEnum(goodsTypeDicEnum.getParentId());
   				}
   			}
   		}
   		return null;
   	}
}
